package com.office.automate.dto.convertors;

import java.util.Properties;

import javax.servlet.http.HttpServletRequest;

import com.office.automate.configuration.property.ConfigurationProperties;
import com.office.automate.frontier.utility.DataConversionUtility;
import com.office.automate.model.report.EmployeeLeaveDetailsRequest;
import com.office.automate.model.report.EmployeeSalaryDetailsRequest;

public class ReportDetailsConvertor {

	private DataConversionUtility dcUtility = new DataConversionUtility();
	private Properties configProp = ConfigurationProperties.getProps();

	public EmployeeLeaveDetailsRequest convertLeaveDetailRequest(HttpServletRequest request) {

		EmployeeLeaveDetailsRequest employeeLeaveDetailsRequest = new EmployeeLeaveDetailsRequest();
		employeeLeaveDetailsRequest.setEmployeeId(dcUtility.convertToLong(request.getParameter("employeeid")));
		employeeLeaveDetailsRequest.setLeaveReportType(request.getParameter("reportType"));
		employeeLeaveDetailsRequest.setFromDate(dcUtility.convertToDate(request.getParameter("fromyear") + "-" + request.getParameter("frommonth") + "-" + request.getParameter("fromday")));
		employeeLeaveDetailsRequest.setToDate(dcUtility.convertToDate(request.getParameter("toyear") + "-" + request.getParameter("tomonth") + "-" + request.getParameter("today")));

		return employeeLeaveDetailsRequest;
	}

	public EmployeeSalaryDetailsRequest convertEmployeeSalaryDetailRequest(HttpServletRequest request) {
		EmployeeSalaryDetailsRequest employeeSalaryDetailsRequest = new EmployeeSalaryDetailsRequest();
		employeeSalaryDetailsRequest.setEmployeeId(dcUtility.convertToLong(request.getParameter("employeeid")));
		employeeSalaryDetailsRequest.setToDate(dcUtility.convertToDate(request.getParameter("periodyear") + "-" + request.getParameter("periodmonth") + "-" + configProp.getProperty("BILLING_DATE_OF_THE_MONTH")));
		int fromMonth = Integer.parseInt(request.getParameter("periodmonth")) - 1;
		int fromYear = Integer.parseInt(request.getParameter("periodyear"));
		if (request.getParameter("periodmonth").equals("1")) {
			fromMonth = 12;
			fromYear = Integer.parseInt(request.getParameter("periodyear")) - 1;
		}
		employeeSalaryDetailsRequest.setFromDate(dcUtility.convertToDate(fromYear + "-" + fromMonth + "-" + configProp.getProperty("BILLING_START_DATE_OF_THE_MONTH")));			
		return employeeSalaryDetailsRequest;
	}
}
